package com.project.dao.impl;

import com.project.bean.CityBean;
import com.project.bean.CountryBean;
import com.project.dao.ICityDao;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;
@Repository
public class CityDaoImpl extends BaseDao implements ICityDao {
    @Override
    public List<CityBean> findByCountry(int countryId) {
        List<CityBean> list = new ArrayList<>();
        this.setConnection();
        try {
            ps = con.prepareStatement("select * from t_city where fk_contry=?");
            ps.setObject(1,countryId);
            rs = ps.executeQuery();
            while(rs.next()){
                CityBean city = new CityBean();
                city.setId(rs.getInt("pk_cityId"));
                city.setCityName(rs.getString("c_name"));
                CountryBean country = new CountryBean();
                country.setId(rs.getInt("fk_contry"));
                city.setCountryBean(country);
                list.add(city);
            }

        } catch (Exception throwables) {
            throwables.printStackTrace();
        }finally{
            this.closeConnection();
        }
        return list;
    }

}
